

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="Yuchen">
  <meta name="keywords" content="">
  <title>sublime乱码解决方法 - Yuchen&#39;s Blog</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/tomorrow-night-eighties.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_pf9vaxs7x7b.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.1.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Yuchen's Blog</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/main4.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2019-03-26 00:00" pubdate>
        2019年3月26日 凌晨
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      820 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      12
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">sublime乱码解决方法</h1>
            
            <div class="markdown-body" id="post-body">
              <p>sublime text 3是一款非常好用的代码编辑器，通过一些配置可以实现多种语言的编译运行，但是也会遇到出现中文显示乱码或者运行程序之后输出结果为乱码，今天就针对这个问题进行一个汇总。</p>
<p>对于代码中中文注释或其他内容出现乱码，通常情况下使用"ConvertToUTF8"这个插件就可以解决问题，如果解决不了，可以尝试在文本文件中另存为，保存编码格式从ASCII修改为UTF-8，复制另存的代码，然后删除之前在sublime中出现乱码的文件，重新创建并将代码粘贴。（如果没有解决，可留言交流或者在看看其他解决方法）</p>
<p>另外一种情况的乱码可以修改环境配置文件，常用参考配置如下，容易采用UTF-8的编码。（"-fexec-charset=gbk"这句一定要加上）</p>
<p>C/C++：</p>
<div class="hljs"><pre><code class="hljs C++"> &#123;
 <span class="hljs-string">&quot;cmd&quot;</span>: [<span class="hljs-string">&quot;gcc&quot;</span>, <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span>, <span class="hljs-string">&quot;-fexec-charset=gbk&quot;</span>,<span class="hljs-string">&quot;-o&quot;</span>, <span class="hljs-string">&quot;$&#123;file_path&#125;/$&#123;file_base_name&#125;&quot;</span>, <span class="hljs-string">&quot;&amp;&quot;</span>, <span class="hljs-string">&quot;start&quot;</span>, <span class="hljs-string">&quot;cmd&quot;</span>, <span class="hljs-string">&quot;/c&quot;</span>, <span class="hljs-string">&quot;$&#123;file_base_name&#125; &amp; echo. &amp; pause&quot;</span>],
 <span class="hljs-string">&quot;file_regex&quot;</span>: <span class="hljs-string">&quot;^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$&quot;</span>,
 <span class="hljs-string">&quot;working_dir&quot;</span>: <span class="hljs-string">&quot;$&#123;file_path&#125;&quot;</span>,
 <span class="hljs-string">&quot;selector&quot;</span>: <span class="hljs-string">&quot;source.c, source.c++&quot;</span>,
 <span class="hljs-string">&quot;shell&quot;</span>: <span class="hljs-literal">true</span>,
 <span class="hljs-string">&quot;encoding&quot;</span>:<span class="hljs-string">&quot;UTF-8&quot;</span>,
&#125;
<span class="hljs-number">2.</span> 保存为g++.sublime-build即可（g++可以改成自己好记的）
<span class="hljs-number">3.</span> 然后ctrl+shift+b选择g++编译</code></pre></div>
<p>或者：</p>
<div class="hljs"><pre><code class="hljs C++">&#123;
    <span class="hljs-string">&quot;encoding&quot;</span>: <span class="hljs-string">&quot;utf-8&quot;</span>,
    <span class="hljs-string">&quot;working_dir&quot;</span>: <span class="hljs-string">&quot;$file_path&quot;</span>,
    <span class="hljs-string">&quot;shell_cmd&quot;</span>: <span class="hljs-string">&quot;g++ -Wall -std=c++11 -fexec-charset=GBK \&quot;$file_name\&quot; -o \&quot;$file_base_name\&quot;&quot;</span>,
    <span class="hljs-string">&quot;file_regex&quot;</span>: <span class="hljs-string">&quot;^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$&quot;</span>,
    <span class="hljs-string">&quot;selector&quot;</span>: <span class="hljs-string">&quot;source.c++&quot;</span>,

    <span class="hljs-string">&quot;variants&quot;</span>: 
    [
        &#123;   
        <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;Run&quot;</span>,
        <span class="hljs-string">&quot;shell_cmd&quot;</span>: <span class="hljs-string">&quot;g++ -Wall -std=c++11 -fexec-charset=GBK \&quot;$file\&quot; -o \&quot;$file_base_name\&quot; &amp;&amp; start cmd /c \&quot;\&quot;$&#123;file_path&#125;/$&#123;file_base_name&#125;\&quot; &amp; pause\&quot;&quot;</span>
        &#125;
    ]
&#125;
</code></pre></div>
<p>Python：</p>
<div class="hljs"><pre><code class="hljs C++">&#123; 
<span class="hljs-string">&quot;cmd&quot;</span>: [<span class="hljs-string">&quot;c:/Python36/python.exe&quot;</span>,<span class="hljs-string">&quot;-u&quot;</span>, <span class="hljs-string">&quot;$file&quot;</span>], <span class="hljs-comment">//自己安装路径</span>
<span class="hljs-string">&quot;file_regex&quot;</span>:<span class="hljs-string">&quot;^[ ]*File \&quot;(...*?)\&quot;, line ([0-9])*&quot;</span>,
<span class="hljs-string">&quot;env&quot;</span>: &#123;<span class="hljs-string">&quot;PYTHONIOENCODING&quot;</span>: <span class="hljs-string">&quot;utf8&quot;</span>&#125;, 
<span class="hljs-string">&quot;selector&quot;</span>: <span class="hljs-string">&quot;source.python&quot;</span> 
&#125;</code></pre></div>
<p>Java:</p>
<p>预先安装JDK并配置环境变量</p>
<ul>
<li>新建JAVA_HOME C:Files.0_181（jdk绝对路径）path 最前面添加%JAVA_HOME%;%JAVA_HOME%;</li>
<li>新建CLASSPATH .;%JAVA_HOME%;%JAVA_HOME%.jar;%JAVA_HOME%.jar</li>
</ul>
<div class="hljs"><pre><code class="hljs C++">    &#123;<span class="hljs-string">&quot;cmd&quot;</span>: [<span class="hljs-string">&quot;javac&quot;</span>, <span class="hljs-string">&quot;-encoding&quot;</span>, <span class="hljs-string">&quot;UTF-8&quot;</span>, <span class="hljs-string">&quot;-d&quot;</span>, <span class="hljs-string">&quot;.&quot;</span>, <span class="hljs-string">&quot;$file&quot;</span>],
    <span class="hljs-string">&quot;file_regex&quot;</span>: <span class="hljs-string">&quot;^(...*?):([0-9]*):?([0-9]*)&quot;</span>,
    <span class="hljs-string">&quot;selector&quot;</span>: <span class="hljs-string">&quot;source.java&quot;</span>,
    <span class="hljs-string">&quot;encoding&quot;</span>: <span class="hljs-string">&quot;GBK&quot;</span>,
    <span class="hljs-comment">//执行完上面的命令就结束</span>
 
    <span class="hljs-comment">// 下面的命令需要按Ctrl+Shift+b来运行</span>
    <span class="hljs-string">&quot;variants&quot;</span>: [&#123;
        <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;Run&quot;</span>,
        <span class="hljs-string">&quot;shell&quot;</span>: <span class="hljs-literal">true</span>,
        <span class="hljs-string">&quot;cmd&quot;</span>: [<span class="hljs-string">&quot;start&quot;</span>, <span class="hljs-string">&quot;cmd&quot;</span>, <span class="hljs-string">&quot;/c&quot;</span>, <span class="hljs-string">&quot;java $&#123;file_base_name&#125; &amp;echo. &amp; pause&quot;</span>],
        <span class="hljs-comment">// /c是执行完命令后关闭cmd窗口,</span>
        <span class="hljs-comment">// /k是执行完命令后不关闭cmd窗口。</span>
        <span class="hljs-comment">// echo. 相当于输入一个回车</span>
        <span class="hljs-comment">// pause命令使cmd窗口按任意键后才关闭</span>
        <span class="hljs-string">&quot;working_dir&quot;</span>: <span class="hljs-string">&quot;$&#123;file_path&#125;&quot;</span>,
        <span class="hljs-string">&quot;encoding&quot;</span>: <span class="hljs-string">&quot;GBK&quot;</span>
    &#125;]
&#125;</code></pre></div>
<p>或者写一个runJava.bat文件放在jdk的bin目录下（具体可自行搜索）：</p>
<div class="hljs"><pre><code class="hljs bat">@<span class="hljs-built_in">ECHO</span> OFF 
<span class="hljs-built_in">cd</span> %~dp1 
<span class="hljs-built_in">ECHO</span> Compiling %~nx1
<span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXIST</span> %~n1.class ( 
<span class="hljs-built_in">DEL</span> %~n1.class 
) 
javac %~nx1 
<span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXIST</span> %~n1.class ( 
<span class="hljs-built_in">ECHO</span> [OUTPUT]:
java %~n1 
)</code></pre></div>
<p>配合下面的配置文件：</p>
<div class="hljs"><pre><code class="hljs C++">&#123;
	<span class="hljs-string">&quot;cmd&quot;</span>: [<span class="hljs-string">&quot;runJava.bat&quot;</span>, <span class="hljs-string">&quot;$file&quot;</span>],
	<span class="hljs-string">&quot;file_regex&quot;</span>: <span class="hljs-string">&quot;^(...*?):([0-9]*):?([0-9]*)&quot;</span>,
	<span class="hljs-string">&quot;selector&quot;</span>: <span class="hljs-string">&quot;source.java&quot;</span>,
	<span class="hljs-string">&quot;encoding&quot;</span>: <span class="hljs-string">&quot;UTF-8&quot;</span>
&#125;</code></pre></div>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E6%95%99%E7%A8%8B/">教程</a>
                    
                  </div>
                
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2019/04/01/2019-04-01-%E5%A6%82%E4%BD%95%E5%AE%89%E8%A3%85Nest-simulator/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">如何安装Nest-simulator</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2019/02/27/2019-02-27-Java%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E7%AC%94%E8%AE%B0(%E4%B8%80)/">
                        <span class="hidden-mobile">《Java核心技术（卷I）》学习笔记 (一)</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="" target="_blank" rel="nofollow noopener"><span>_____</span></a>
      <i class="iconfont icon-love"></i>
      <a href="" target="_blank" rel="nofollow noopener">
        <span>digua</span></a>
    </div>
    

    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>







  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "sublime乱码解决方法&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>




















</body>
</html>
